<template>
  <div>
    <Modal v-model="couponPop" width="760" class-name="vertical-center-modal" :closable="false">
      <div slot="header" class="head-pop">
        <div class="pop-head">
          <div class="pop-tit">{{ $t('user.expired_date_tit_text') }}</div>
          <Icon type="md-close" size="26" color="#242424" class="close" @click="cancelBtn()" />
        </div>
        <div class="expired-tip">
          <Icon type="md-information-circle" color="#FF186B" size="18" style="margin-right: 8px;" />
          {{ $t('user.expired_date_tip_text') }}&nbsp;
          <span class="use-text" @click="goUse()"><span class="text">{{ $t('user.go_use') }}</span>
            <Icon type="ios-arrow-forward" color="#FF186B" size="18" />
          </span>
        </div>
      </div>
      <Row :gutter="32" class="box" v-if="couponDataList && couponDataList.length > 0">
        <Col span="12" v-for="(item, index) in couponDataList" :key="index">
        <div class="item" :class="getClass(item)">
          <img src="@/assets/images/user/expired.png" class="expired-icon"
            v-if="item.status == 'EXPIRED' && item.expiredAt <= now" alt="">
          <div class="cover-up" v-if="item.status != 'UNUSED' || item.isAvailable == false"></div>
          <div class="head-wrap">
            <div class="type-tit">
              <img :src="iconCom(item)" class="icon-img" alt="">
              <div class="type-name">{{ compName(item) }}</div>
            </div>
            <div></div>
          </div>
          <div class="gradient" />
          <div class="content-sty">
            <div class="head">
              <span class="label" v-if="item.type != 'ZKQ'">{{ userInfo.currencySymbol }}</span>
              <span class="val">{{ item.type == 'ZKQ' ? `${bigTimes((item.discountShowOFF || 0), 10)}%` :
                item.discountShowOFF || 0
              }}</span>
              <span class="unit">OFF</span>
            </div>
            <div class="btn">{{ `${$t('personal.MinFreight')} ${userInfo.currencySymbol}${item.minPrice || 0}
              ${userLanguage.code == 'zh_CN' ? $t('personal.required') : ''}` }}</div>
          </div>
          <div class="time">{{ `${item.startTime || ''} ~ ${item.endTime || ''}` }}</div>
          <div class="un-reason"
            v-if="(item.status != 'UNUSED' || item.isAvailable == false) && item.status != 'EXPIRED'">
            <div class="text">{{ item.noAvailableReason || '——' }}</div>
          </div>
          <div class="tip" v-else>{{ item.description || '——' }}</div>
        </div>
        </Col>
      </Row>
      <div slot="footer" class="footer-sty">
        <div></div>
        <div class="handle-sty">
          <div class="handle-btn" @click="cancelBtn()">{{ $t('order.know_tip_text') }}</div>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script>
import { bigTimes } from "@/common/digital-computation";
import dayjs from 'dayjs';
export default {
  props: ['userInfo', 'userLanguage'],
  data() {
    return {
      couponPop: false,
      active: '',
      infoVal: {},
      couponDataList: [],
      now: Date.now(),
      expressIcon: require('@/assets/images/home/express_icon.png'),
      orderIcon: require('@/assets/images/home/order_icon.png'),
    }
  },
  methods: {
    dayjs,
    bigTimes,
    getClass(item) {
      if (item.targetObject === 'EXPRESS') {
        return 'express-item';
      } else if (item.targetObject === 'ORDER') {
        return 'order-item';
      } else {
        return ''
      }
    },
    textClass(item) {
      if (item.targetObject === 'EXPRESS') {
        return 'express-text';
      } else if (item.targetObject === 'ORDER') {
        return 'order-text';
      } else {
        return ''
      }
    },
    iconCom(item) {
      if (item.targetObject === 'EXPRESS') {
        return this.expressIcon;
      } else if (item.targetObject === 'ORDER') {
        return this.orderIcon;
      } else {
        return ''
      }
    },
    compName(item) {
      if (item.targetObject === 'EXPRESS') {
        return this.$t('user.express_coupon_tit');
      } else if (item.targetObject === 'ORDER') {
        return this.$t('user.order_coupon_tit');
      } else {
        return ''
      }
    },
    textSty(item) {
      if (item.targetObject === 'EXPRESS') {
        return 'express-text';
      } else if (item.targetObject === 'ORDER') {
        return 'order-text';
      } else {
        return ''
      }
    },
    open(item) {
      this.couponDataList = item;
      this.couponPop = true;
    },
    cancelBtn() {
      this.couponPop = false;
    },
    goUse() {
      this.couponPop = false;
      setTimeout(() => {
        this.$router.push(`/user/assets?${"from=name2"}`)
      }, 1000)
    }
  }
}
</script>

<style scoped lang="less">
:deep(.ivu-modal-content) {
  border-radius: 12px;

  .ivu-modal-header {
    border: none;
    padding: 0;
  }

  .ivu-modal-body {
    padding: 0 42px;
  }

  .ivu-modal-footer {
    padding: 24px 42px;
    border: none;
  }
}

.vertical-center-modal {
  display: flex;
  align-items: center;
  justify-content: center;

  .head-pop {
    border-radius: 12px 12px 0 0;

    .pop-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin: 0 42px;
      padding-top: 32px;

      .pop-tit {
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 24px;
        color: #1E1714;
        line-height: 28px;
      }

      .close {
        cursor: pointer;
      }
    }

    .expired-tip {
      margin: 12px 42px 20px 42px;
      display: inline-flex;
      align-items: center;
      padding: 12px 16px;
      background: #FFEEF4;
      border-radius: 6px;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 16px;
      color: #1E1714;
      line-height: 18px;

      .use-text {
        display: inline-flex;
        align-items: center;
        cursor: pointer;

        .text {
          font-weight: 400;
          font-size: 16px;
          color: #FF186B;
          line-height: 18px;
          border-bottom: 1px solid #FF186B;
        }
      }
    }
  }

  .box {
    overflow: auto;
    height: 400px;

    .item {
      padding: 24px 0 12px 0;
      min-height: 203px;
      margin-bottom: 20px;
      position: relative;

      .expired-icon {
        width: 94px;
        height: 67px;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 4;
      }

      .cover-up {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 3;
        background: #FFFFFF;
        opacity: 0.5;
        filter: grayscale(100%);
        cursor: no-drop !important;
      }

      .head-wrap {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-left: 24px;
        margin-right: 24px;

        .type-tit {
          display: flex;
          align-items: center;
          gap: 8px;

          .icon-img {
            width: 16px;
            height: 16px;
          }

          .type-name {
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            font-size: 14px;
            color: #FFFFFF;
            line-height: 16px;
          }
        }
      }


      .time {
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #ffffffb3;
        line-height: 16px;
        margin-top: 8px;
        margin-left: 24px;
      }

      .express-text {
        color: #FF6A25;
        font-weight: 600;
      }

      .order-text {
        color: #FF1140;
        font-weight: 600;
      }

      .gradient {
        border-bottom: 2px dashed #ffffffb3;
        margin: 24px 24px;
      }

      .content-sty {
        display: flex;
        margin-left: 24px;
        margin-right: 24px;


        .head {
          margin-bottom: 5px;
          color: #FFFFFF;
          text-align: center;
          line-height: 32px;
          font-weight: bold;

          .label {
            font-size: 32px;
          }

          .val {
            font-size: 32px;
            margin-left: 4px;
          }

          .unit {
            font-size: 24px;
            margin-left: 8px;
          }
        }

        .btn {
          font-size: 14px;
          display: flex;
          align-items: center;
          justify-content: center;
          color: #FFFFFF;
          display: inline-flex;
          margin-left: 8px;
        }
      }

      .tip {
        font-family: PingFang SC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #FFFFFF;
        line-height: 16px;
        margin-top: 12px;
        margin-left: 24px;
        margin-right: 24px;
      }

      .un-reason {
        background: #F7F9FC;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;

        .text {
          font-weight: 500;
          font-size: 16px;
          color: #767B93;
          line-height: 16px;
          margin: 12px 24px;
        }
      }
    }

    .express-item {
      background: url(@/assets/images/home/express_bg.png) no-repeat;
      background-size: 100% 100%;
    }

    .order-item {
      background: url(@/assets/images/home/order_bg.png) no-repeat;
      background-size: 100% 100%;
    }
  }

  .box::-webkit-scrollbar {
    display: none;
  }

  .footer-sty {
    display: flex;
    justify-content: space-between;

    .handle-sty {
      display: flex;
      align-items: center;
      gap: 24px;

      .handle-btn {
        min-width: 144px;
        padding: 12px 40px;
        background: #1E1714;
        border-radius: 8px 8px 8px 8px;
        font-weight: 400;
        font-size: 16px;
        color: #FFFFFF;
        text-align: center;
        cursor: pointer;
      }
    }
  }
}
</style>